#ifndef SENSOR_ARCHIVES_H
#define SENSOR_ARCHIVES_H

#include <stdint.h>
#include "virtual_flash.h"

#define SENSOR_ARCHIVE_NUMS    (127)//支持的表档案个数

#define ARCHIVES_FROM            SENSOR_ARCHIVES_ADDR //
#define ARCHIVES_SIZE            SENSOR_ARCHIVES_SIZE // 2K(6*256)//
#define ARCHIVES_VALID_ADDR      (ARCHIVES_FROM + ARCHIVES_SIZE)//

#define SENSOR_MAGIC     (0xAA55u)
#define SENSOR_VALID     (0xFE)
#define SENSOR_INVALID   (0XFF)

typedef struct
{
    uint16_t  magic;
    uint16_t  crc;
} sensor_hdr_t;

typedef struct
{
    uint8_t aid[4];
    uint8_t seq;
    uint8_t flag;
    uint8_t extra[2];
}sensor_infor_t;

typedef struct
{
    sensor_hdr_t    sensor_hdr;
    sensor_infor_t  sensor_infor[SENSOR_ARCHIVE_NUMS];
}__attribute__((aligned(4)))sensor_archives_t;

#define  SENSOR_HDR_SIZE      sizeof(sensor_hdr_t)
#define  SENSOR_INFOR_SIZE    (sizeof(sensor_infor_t)*SENSOR_ARCHIVE_NUMS)
#define  SENSOR_INFOR_ADDR(s) ((uint8_t*)&s + SENSOR_HDR_SIZE)

extern sensor_archives_t  sensor_archives;

void sensor_archives_load(void);
void sensor_archives_save(void);
void sensor_archives_show(uint8_t sensor_map);

int is_in_sensor_archives(uint8_t aid[]);
int save_new_sensor_infor(uint8_t aid[]);


#endif // SENSOR_ARCHIVES_H
